package cn.bupt.adt.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.bupt.adt.dao.autogenerate.AdminUserMapper;
import cn.bupt.adt.entity.autogenerate.AdminUser;
import cn.bupt.adt.entity.autogenerate.AdminUserExample;
import cn.bupt.adt.entity.autogenerate.Carousel;
import cn.bupt.adt.entity.autogenerate.CarouselExample;
import cn.bupt.adt.model.AdminUserModel;
import cn.bupt.adt.service.IAdminUserService;
import cn.bupt.adt.util.MD5Util;


@Service
public class AdminUserServiceImpl implements IAdminUserService{
	
	@Autowired 
	AdminUserMapper adminUserMapper;
	@Override
	public Boolean updateSecret(AdminUserModel adminUser){
		try {
			if(AdminUserModel.getPasswd2().equals(AdminUserModel.getPasswd1())){

				adminUser.setPasswd(MD5Util.MD5(AdminUserModel.getPasswd1()));
				int i =  adminUserMapper.updateByPrimaryKeySelective(adminUser);
				if(i<=0){
					return false;
				}
				else 
					return true;
			}
			else 
				return false;
		}catch (Exception e) {
			// TODO: handle exception
			return false;
		}
	}
	
	@Override
	public Boolean updateInfo(AdminUserModel adminUser){
		try {
			int i =  adminUserMapper.updateByPrimaryKeySelective(adminUser);
			if(i<=0){
				return false;
			}
			else 
				return true;
			
		}catch (Exception e) {
			// TODO: handle exception
			return false;
		}
	}
	@Override
	public AdminUser getAdminUserById(int id) {
		return adminUserMapper.selectByPrimaryKey(id);
	}
	
	@Override
	public List<AdminUser> getAllAdminUser() {
		return adminUserMapper.selectByExample(new AdminUserExample());
	}
	
	@Override
	public Integer getdoctorNum() {
		return adminUserMapper.selectDoctoNum();
	}
	@Override
	public Integer getonGingOrderNum() {
		return adminUserMapper.selectOnGoingOrderNum();
	}
	@Override
	public Integer getallOrderNum() {
		return adminUserMapper.selectOrderNum();
	}
}
